package com.trsj.lnsj.entity;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface ActivityRepo extends JpaRepository<ActivityDTO, Long> {

	Page<ActivityDTO> findByType(String type,Pageable page);
	Page<ActivityDTO> findByUserId(String type,Pageable page);
	Page<ActivityDTO>findByNameLikeOrAddressLike(String name,String address,Pageable page);
	Page<ActivityDTO> findByActOrganiser(String actOrganiser,Pageable page);
	List<ActivityDTO> findByNameLike(String name);
    @Query(value="select t.id , t.access , t.act_amount , user.nickname as act_organiser ,t.act_status , t.address , t.content , t.create_date , t.end_time, t.group_id , t.image_addr, t.limit_persons, t.name , t.price , t.signup_number, t.start_time , t.type, t.update_date,t.LAL,t.phone_number from tab_activity t left join tab_user user on t.act_organiser=user.happy_no where t.type= :type limit :start,:size",nativeQuery = true)
	List<ActivityDTO> findByTypeSqlQuery(@Param("type")String type,@Param("start")int start,@Param("size")int size);
    @Query(value="select t.id , t.access , t.act_amount , user.nickname as act_organiser ,t.act_status , t.address , t.content , t.create_date , t.end_time, t.group_id , t.image_addr, t.limit_persons, t.name , t.price , t.signup_number, t.start_time , t.type, t.update_date,t.LAL,t.phone_number  from tab_activity t left join tab_user user on t.act_organiser=user.happy_no limit :start,:size",nativeQuery = true)
    List<ActivityDTO> findAllSqlQuery(@Param("start")int start,@Param("size")int size);
    @Query(value="select t.id , t.access , t.act_amount , user.nickname as act_organiser ,t.act_status , t.address , t.content , t.create_date , t.end_time, t.group_id , t.image_addr, t.limit_persons, t.name , t.price , t.signup_number, t.start_time , t.type, t.update_date,t.LAL,t.phone_number  from tab_activity t left join tab_user user on t.act_organiser=user.happy_no where t.name like :q or t.address like :q limit :start,:size",nativeQuery = true)
    List<ActivityDTO> findByKeyWordSqlQuery(@Param("q")String keywordPageable,@Param("start")int start,@Param("size")int size);
}
